<?php
function save_thesis($userid,$thesistitle,$publishplace,$publishdate,$searchcd){
	$query="INSERT INTO 
			thesis (
			TITLE,
			PUBLISHER,
			PUBLISHDATE,
			SEARCHCD,
			AUTHOR
			) VALUES(
			'$thesistitle',
			'$publishplace',
			'$publishdate',
			'$searchcd',
			$userid)";
	mysql_query($query);
}
function get_teacher_thesis($userid,$key_year,$key_sort){
	$query="SELECT 
			thesis.TITLE,
			thesis.PUBLISHDATE,
			thesis.PUBLISHER,
			thesis.SEARCHCD,
			thesis.COMMITDATE,
			thesis.AUTHOR,
			user.USERNAME 
			FROM thesis 
			LEFT JOIN user 
			ON thesis.AUTHOR=user.USERID 
			WHERE 
			EXTRACT(YEAR FROM PUBLISHDATE)=$key_year 
			AND 			
			thesis.AUTHOR IN(SELECT USERID FROM user WHERE USERGROUP=$userid) 
			ORDER BY
			$key_sort DESC 
			";
	$result=mysql_query($query);
	return $result;
}
function get_admin_thesis($key_year,$key_teacher,$key_sort){
	$query="SELECT 
			thesis.TITLE,
			thesis.PUBLISHDATE,
			thesis.PUBLISHER,
			thesis.SEARCHCD,
			thesis.COMMITDATE,
			thesis.AUTHOR,
			user.USERNAME,
			user.USERGROUP 
			FROM thesis 
			LEFT JOIN user 
			ON thesis.AUTHOR=user.USERID 
			WHERE 
			EXTRACT(YEAR FROM PUBLISHDATE)=$key_year 
			AND 
			user.USERGROUP=$key_teacher
			ORDER BY $key_sort DESC 
			";
	$result=mysql_query($query);
	return $result;
}

function get_teacher_name($userid){
	$query="SELECT USERNAME AS TEACHERNAME FROM user WHERE USERID=$userid";
	$result=mysql_query($query);
	return $result;
}
function get_admin_count(){
	$query="SELECT COUNT(thesis.TITLE) AS PAGENUMS from thesis LEFT JOIN user ON thesis.AUTHOR=user.USERID";
	$result=mysql_query($query);
	return $result;
}
function get_teacher_count(){
	$query="";
	$result=mysql_query($query);
	return $result;
}
function get_teacher_list(){
	$query="SELECT USERID,USERNAME FROM user WHERE LEVEL=".TEACHER;
	$result=mysql_query($query);
	return $result;	
}
?>